/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.filters;

import biofilter.sources.*;
import biofilter.exceptions.InvalidRecordException;
import biofilter.records.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author qvh
 */
public class CompositeFilterTest {

    public CompositeFilterTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    RecordsFile fnrf = null;
    @Before
    public void setUp() {
        try {
            System.out.println("running in " + System.getProperty("user.dir"));
            String recordClassName = "biofilter.records.MyStubRecord";            
            fnrf = new RecordsFile("test/testdata/emptyfile", recordClassName);
            fnrf.createRecordClass(recordClassName);
        } catch (InvalidRecordException ex) {
            Logger.getLogger(CompositeFilterTest.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    /**
     * Test of setSource method, of class CompositeFilter.
     */
    @Test
    public void testSetSource() {
        System.out.println("setSource");
        CompositeFilter instance = new CompositeFilter();
        instance.setSource(fnrf);
        RecordsFile rf = (RecordsFile) instance.getSource();
        assertEquals(rf.getClass(), fnrf.getClass());
    }

    /**
     * Test of getRecord method, of class CompositeFilter.
     */
    @Test
    public void testGetRecordSourceOnly() throws Exception {
        System.out.println("getRecordSourceOnly");
        String recordClassName = "biofilter.records.FileNameRecord";
        fnrf = new RecordsFile("test/testdata/filename_recordsfile", recordClassName);
        System.out.println(fnrf.getRecord().get()  );

        CompositeFilter instance = new CompositeFilter();
        instance.setSource(fnrf);
        String expResult = "/etc/hosts";
        RecordsFile fnrf = (RecordsFile) instance.getSource();
        //System.out.println(fnrf.getRecord().get()  );
        Record res =  (Record) instance.getRecord();
        String result = res.get();
        assertEquals(expResult, result);
    }

        /**
     * Test of getRecord method, of class CompositeFilter.
     */
    @Test
    public void testGetRecordOneFilter() throws Exception {
        System.out.println("getRecordOneFilter");
        String recordClassName = "biofilter.records.FileNameRecord";
        fnrf = new RecordsFile("test/testdata/filename_recordsfile", recordClassName);
        System.out.println(fnrf.getRecord().get()  );
        ToUpperFilter tuf = new ToUpperFilter();
        CompositeFilter instance = new CompositeFilter();
        instance.setSource(fnrf);
        instance.addFilter(tuf);
        String expResult = "/ETC/HOSTS";
        RecordsFile fnrf = (RecordsFile) instance.getSource();
        //System.out.println(fnrf.getRecord().get()  );
        Record res =  (Record) instance.getRecord();
        String result = res.get();
        assertEquals(expResult, result);
    }

}
